package com.atguigu.guli.service.vod.controller;

import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.vod.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author lsystart
 * @create2021-11-05 16:40
 */
@CrossOrigin
@RestController
@RequestMapping("/admin/vod")
public class MediaController {

    @Autowired
    VideoService videoService;

    @PostMapping("/upload")
    public R upload(MultipartFile file){
        String originalFilename = file.getOriginalFilename();
        InputStream inputStream = null;
        try {
            inputStream = file.getInputStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        String videoId = videoService.uploadVideo(inputStream, originalFilename);
        return R.ok().data("videoId",videoId);
    }

    @GetMapping("/getPlayAuth/{videoId}")
    public R getPlayAuth(@PathVariable String videoId){
        String playAuth = videoService.getPlayAuth(videoId);
        return R.ok().data("playAuth",playAuth);
    }
}
